package lq.cloud.febsservertest.controller;

import lq.cloud.febsservertest.service.IHelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * @program: cloud-study
 * @description:
 * @author: LQ
 * @create: 2020-09-23 17:45
 */
@RestController
public class TestController {
    @Autowired
    private IHelloService helloService;

    @GetMapping("test1")
    @PreAuthorize("hasAnyAuthority('user:add')")
    public String test1(){
        return "拥有'user:add'权限";
    }

    @GetMapping("test2")
    @PreAuthorize("hasAnyAuthority('user:update')")
    public String test2(){
        return "拥有'user:update'权限";
    }

    @GetMapping("user")
    public Principal currentUser(Principal principal) {
        return principal;
    }

    /**
     * 提供接口供调用
     * 在helloService中通过feign调用STUDY_SERVER_SYSTEM服务中的请求接口
     * @param name
     * @return
     */
    @GetMapping("hello")
    public String hello(String name){
        return this.helloService.hello(name);
    }
}
